home *** CD-ROM | disk | FTP | other *** search
Text File | 2005-05-11 | 3.3 KB | 116 lines | [TEXT/FB^e] |
-
- '~'A
- ' Runtime : Rntm Appearance.Incl
- ' CPU : Carbon
- ' CALL Req'd : Off
- ' No Re-DIM'd Vars : On
- ' DIM'd Vars Only : On
- ' Debug Labels : On
- ' Register Vars : On
- '~'B
-
- /*
- this shows how to display a file [via filespec] in the finder
- from your application. very cool!
-
- original code by waverly edwards
-
- this is the code used in the editor when you control click an
- item in the editor's project window to view it in the finder.
-
- items collected into a single file for upload by staz on 11 may 05 by staz
- */
-
- end globals
-
- _kAEMiscStandards = _"misc"
- _kAEMakeObjectsVisible = _"mvis"
- _kAECanSwitchLayer = 0x00000040/* interaction may switch layer */
- _kAEAlwaysInteract = 0x00000030
-
- register off
- local mode
- local fn findProcess( type as OSType, creator as OSType, psnPtr as ptr to ProcessSerialNumber )
- '~'9
- /*
- if process of specified type and creator is running, return _noErr and
- fill in the ProcessSerialNumber; else return _procNotFound or _paramErr as appropriate
- */
- dim processInfo as ProcessInfoRec
- dim retCode as short
-
- processInfo.processInfoLength = sizeof( ProcessInfoRec ) // Set up the process info rec
- processInfo.processName = _nil
- processInfo.processAppSpec = _nil
- psnPtr.highLongOfPSN = 0 // to get first process in the list
- psnPtr.lowLongOfPSN = 0
- while ( fn GetNextProcess( #psnPtr ) == _noErr ) // Index the list until process found or all searched
- long if ( fn GetProcessInformation( #psnPtr, processInfo ) )
- retCode = _paramErr
- exit fn
- end if
- long if ( processInfo.processSignature == creator ) and ( processInfo.processType == type )
- retCode = _noErr
- exit fn
- end if
- wend
- retCode = _procNotFound
- end fn = retCode
-
- local mode
- local fn showFileInFinder(inSpec as ^FSSpec)
- '~'9
- register on
- dim as ProcessSerialNumber finderPSN
- dim as AppleEvent aEvent, reply
- dim as AEDesc addrDesc
- dim as OSErr err,ignore
-
- // OUCH! That took a long time to work out
-
- // locate the running Finder
- err = fn findProcess(_"FNDR",_"MACS",finderPSN)
- if (err) then exit "bail"
-
- // create an address descriptor for the Finder
- err = fn AECreateDesc(_typeProcessSerialNumber, finderPSN, sizeof(finderPSN), addrDesc)
- if (err) then exit "bail"
-
- // create the event, addressed to the Finder
- err = fn AECreateAppleEvent(_kAEMiscStandards, _kAEMakeObjectsVisible, addrDesc,_kAutoGenerateReturnID, _kAnyTransactionID, aEvent)
- if (err) then exit "bail"
-
- // add the direct parameter
- err = fn AEPutParamPtr(aEvent, _keyDirectObject, _typeFSS, #inSpec, sizeof(FSSpec))
- if (err) then exit "bail"
-
- // send the event
- err = fn AESend(aEvent,reply,_kAECanSwitchLayer+_kAEAlwaysInteract+_kAENoReply,_kAENormalPriority,_kAEDefaultTimeout,_nil,_nil)
- if (err) then exit "bail"
-
- // bring Finder to front at next opportunity
- err = fn SetFrontProcess(finderPSN)
-
- "bail"
- ignore = fn AEDisposeDesc( aEvent )
- ignore = fn AEDisposeDesc( reply )
- ignore = fn AEDisposeDesc( addrDesc )
-
- end fn = err
-
-
-
- '~'6
- // example -- here's how to use it
- '~'6
- dim as fsspec fs
- dim as str255 fName
- gFBUseNavServices = _zTrue
- fName = files$ ( _fsSpecOpen , , "Select a file, I'll show it to you in the Finder" , fs )
-
- long if fName[0]
- fn showFileInFinder ( fs )
- end if
-
-
-